bitkeeper revision 1.1662.1.12 (42a4a819BMGTxn8p4rsFdp44pCQ_Og)
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Mon, 6 Jun 2005 19:46:33 +0000 (19:46 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Mon, 6 Jun 2005 19:46:33 +0000 (19:46 +0000)
netif.py:
  Use macFromString, macToString.
mac.py:
  new file
Signed-off-by: Mike Wray <mike.wray@hp.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
.rootkeys
tools/python/xen/util/mac.py [new file with mode: 0644]
tools/python/xen/xend/server/netif.py

index 3759be63f91f6ffb7fc0c01dafcbb00baa6ccc7d..77b06993c5bfd15f91d6b34ddf0d21a2876126a5 100644 (file)
--- a/.rootkeys
+++ b/.rootkeys
 4270e4efFg3wHCCxXpA0h6yoMTkeSQ tools/python/xen/util/blkif.py
 4055ee4dwy4l0MghZosxoiu6zmhc9Q tools/python/xen/util/console_client.py
 40c9c468IienauFHQ_xJIcqnPJ8giQ tools/python/xen/util/ip.py
+42a4a80aiq_AT5whiSw-fKhNhRKITw tools/python/xen/util/mac.py
 41dde8b0yuJX-S79w4xJKxBQ-Mhp1A tools/python/xen/util/memmap.py
 4288c6fcB1kUAqX0gzU85GGxmamS4Q tools/python/xen/util/process.py
 4059c6a0pnxhG8hwSOivXybbGOwuXw tools/python/xen/util/tempfile.py
diff --git a/tools/python/xen/util/mac.py b/tools/python/xen/util/mac.py
new file mode 100644 (file)
index 0000000..47dffd8
--- /dev/null
@@ -0,0 +1,11 @@
+
+from string import join, split
+
+def macToString(mac):
+    return ':'.join(map(lambda x: "%02x" % x, mac))
+
+def macFromString(str):
+    mac = [ int(x, 16) for x in str.split(':') ]
+    if len(mac) != 6:
+        raise ValueError("invalid mac: %s" % str)
+    return mac
index ceb2f912a3720b796ca3f427692163f664a8840f..157490f5a2d175e212b6a88516a9f91dec5058d8 100755 (executable)
@@ -4,6 +4,8 @@
 
 import random
 
+from xen.util.mac import macFromString, macToString
+
 from xen.xend import sxp
 from xen.xend import Vifctl
 from xen.xend.XendError import XendError, VmError
@@ -49,15 +51,19 @@ class NetDev(Dev):
     def _get_config_mac(self, config):
         vmac = sxp.child_value(config, 'mac')
         if not vmac: return None
-        mac = [ int(x, 16) for x in vmac.split(':') ]
-        if len(mac) != 6: raise XendError("invalid mac: %s" % vmac)
+        try:
+            mac = macFromString(vmac)
+        except:
+            raise XendError("invalid mac: %s" % vmac)
         return mac
 
     def _get_config_be_mac(self, config):
         vmac = sxp.child_value(config, 'be_mac')
         if not vmac: return None
-        mac = [ int(x, 16) for x in vmac.split(':') ]
-        if len(mac) != 6: raise XendError("invalid backend mac: %s" % vmac)
+        try:
+            mac = macFromString(vmac)
+        except:
+            raise XendError("invalid backend mac: %s" % vmac)
         return mac
 
     def _get_config_ipaddr(self, config):
@@ -212,12 +218,12 @@ class NetDev(Dev):
     def get_mac(self):
         """Get the MAC address as a string.
         """
-        return ':'.join(map(lambda x: "%02x" % x, self.mac))
+        return macToString(self.mac)
 
     def get_be_mac(self):
         """Get the backend MAC address as a string.
         """
-        return ':'.join(map(lambda x: "%02x" % x, self.be_mac))
+        return macToString(self.be_mac)
 
     def vifctl_params(self, vmname=None):
         """Get the parameters to pass to vifctl.